package online.heycm.platform.rocketmq.common.entity;

import online.heycm.platform.common.tools.Jackson;

/**
 * 事件上下文
 *
 * @author heycm
 * @since 2023/11/29 20:54
 */
public class Context {

    /**
     * 上下文ID
     */
    private String contextId;

    /**
     * 数据
     */
    private String data;

    public Context() {}

    public Context(String data) {
        this.data = data;
    }

    public Context(String contextId, String data) {
        this.contextId = contextId;
        this.data = data;
    }

    public static Context of(String data) {
        return new Context(data);
    }

    public static Context of(String contextId, String data) {
        return new Context(contextId, data);
    }

    public String getContextId() {
        return contextId;
    }

    public void setContextId(String contextId) {
        this.contextId = contextId;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return toJson();
    }

    public String toJson() {
        return Jackson.toJson(this);
    }
}
